﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DrinkTest.Question;

namespace DrinkTest.Answer
{
    class Sofia:IDrinkTest
    {
        public struct tdrink
        {
            public int Sat;
            public int Amount;
            public int Num;
        }

        public long GetSumSat(int[] S, int[] A)
        {
            if (S.Length != A.Length) return 0;

            int N = S.Length;
            int[] X = new int[N];
            int Asum = 0;
            int T = 100;
            long result = 0;

            for (int i = 0; i < N; i++) Asum += A[i];
            if (T > Asum) return -1;

            ArrayList alist = new ArrayList();
            for (int i = 0; i < N; i++)
            {
                tdrink tt = new tdrink();
                tt.Sat = S[i];
                tt.Amount = A[i];
                tt.Num = i;
                alist.Add(tt);
            }

            MyComparer comparer = new MyComparer();
            alist.Sort(comparer);
            alist.Reverse();

            int Xsum = 0;

            foreach (tdrink ntt in alist)
            {
                Xsum += ntt.Amount;
                if (Xsum < T || Xsum == T)
                    result += ntt.Sat * ntt.Amount;
                else
                {
                    result += ntt.Sat * (T - Xsum + ntt.Amount);
                    break;
                }
            }
            return result;
        }

        public class MyComparer : IComparer
        {
            public int Compare(object a, object b)
            {
                tdrink a1 = (tdrink)a;
                tdrink b1 = (tdrink)b;
                if (a1.Sat > b1.Sat)
                    return 1;
                else if (a1.Sat < b1.Sat)
                    return -1;
                else return 0;
            }
        } 
    }
}
